package com.common;

import java.io.Serializable;
import java.math.BigDecimal;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * 百分比
 * 
 * @author：<a href="mailto:beier.zheng@yeepay.com">郑贝尔</a>
 * @since：2012-6-13 下午05:45:48
 * @version:
 */
public class Percent implements Serializable {

	private static final long serialVersionUID = -4065855190916543629L;

	/**
	 * 百分比值
	 */
	private BigDecimal value;

	/**
	 * 无参构造器
	 */
	public Percent() {
		super();
	}

	public Percent(BigDecimal value) {
		if (value == null) {
			throw new RuntimeException("无效的百分比值[value=" + value + "]");
		}
		// 保留小数点后6位有效数字
		this.value = value.setScale(6, BigDecimal.ROUND_HALF_UP);
	}

	public Percent(String value) {
		this(new BigDecimal(value));
	}

	public Percent(float value) {
		this(new BigDecimal(value));
	}

	public Percent(double value) {
		this(new BigDecimal(value));
	}

	public BigDecimal getValue() {
		return value;
	}

	public void setValue(BigDecimal value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

}
